import { Catch, MidwayHttpError } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { MidwayValidationError } from '@midwayjs/validate';

export class MissTargetError extends MidwayHttpError {
  constructor(message: string) {
    super(message, 800);
  }
}
@Catch(MissTargetError)
export class MissTargetErrorFilter {
  async catch(err: MissTargetError, ctx: Context) {
    ctx.status = err.status;
    return err.message;
  }
}
export class BillStateError extends MidwayHttpError {
  constructor(message: string) {
    super(message, 888);
  }
}
@Catch(BillStateError)
export class BillStateErrorFilter {
  async catch(err: BillStateError, ctx: Context) {
    ctx.status = err.status;
    return err.message;
  }
}
export class LoginError extends MidwayHttpError {
  constructor(message: string) {
    super(message, 600);
  }
}
@Catch(LoginError)
export class LoginErrorFilter {
  async catch(err: LoginError, ctx: Context) {
    ctx.status = err.status;
    return err.message;
  }
}

// 捕获框架 异常 MidwayValidationError
@Catch(MidwayValidationError)
export class MidwayValidationErrorFilter {
  async catch(err: MidwayValidationError, ctx: Context) {
    ctx.status = 701;
    return err.message;
  }
}
